package demo;

import com.google.gson.*;
import java.io.IOException;
import java.util.logging.Logger;
import java.util.*;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AdminTrackDataServlet extends HttpServlet {
	private static final Logger log = Logger.getLogger(MyTrackServlet.class.getName());	
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		TrackDataAO ao = new TrackDataAO();
		Gson gson = new Gson();
		String json = null;
		int max = 100;
		
		
		if (req.getParameter("type") != null) {
			String maxStr = req.getParameter("type");
			try {
				max = Integer.parseInt(maxStr);
			} catch (NumberFormatException e) {
				
			}
		
			
			List<MapData> trying = ao.getAllData(max);

			json = gson.toJson(trying);
		}
		else
		{
			List<MapData> trying = ao.getAllData(max);

			json = gson.toJson(trying);
		}
		
		resp.setContentType("text/plain");
		resp.getWriter().println("{\"aaData\":" + json +"}");	
	
		
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		
		doGet(req,resp);
	}

}
